<?php

namespace Trawind\Basics\Enums;

use Illuminate\Support\Facades\Request;
use Trawind\Helpers\UserHelper;

/**
 * Class ServiceDomain
 * @method static ACCOUNT_DOMAIN(?int $tenantId = null)
 * @method static STORAGE_DOMAIN(?int $tenantId = null)
 * @method static USER_DOMAIN(?int $tenantId = null)
 * @method static FINANCE_DOMAIN(?int $tenantId = null)
 * @method static PURCHASE_DOMAIN(?int $tenantId = null)
 * @method static INVENTORY_DOMAIN(?int $tenantId = null)
 * @method static PRODUCT_DOMAIN(?int $tenantId = null)
 * @method static NOTIFICATION_DOMAIN(?int $tenantId = null)
 * @method static SALE_DOMAIN(?int $tenantId = null)
 * @method static REPORT_DOMAIN(?int $tenantId = null)
 * @method static EXTENSION_DOMAIN(?int $tenantId = null)
 *
 * @package Trawind\Basics\Enums
 */
final class ServiceDomain extends BaseEnumerate
{

    const SERVICE_ENUM = [
        'account_domain' => 'account',
        'storage_domain' => 'storage',
        'user_domain' => 'user',
        'finance_domain' => 'finance',
        'purchase_domain' => 'purchase',
        'inventory_domain' => 'inventory',
        'product_domain' => 'product',
        'notification_domain' => 'notification',
        'sale_domain' => 'sale',
        'report_domain' => 'report',
        'extension_domain' => 'extension',
    ];


    /**
     * @param $name
     * @param $arguments
     * @return string
     */
    public static function __callStatic($name, $arguments)
    {
        $tenantId = array_shift($arguments) ?? UserHelper::tenantId();
        $tenantPrefix = $tenantId ? ($tenantId.'.') : '';
        $domain = self::SERVICE_ENUM[strtolower($name)].'.trawindcloud.com';
//        $port = Request::getPort();

        return request()->getScheme().'://'.$tenantPrefix.config('app.env').'.'.$domain;
//        return request()->getScheme().'://'.$tenantPrefix.config('app.env').'.'.$domain . ($port ? ':' . $port : '');
    }

}
